﻿/**
* @author Alexander Rindo
* @project Flashview
* @version 0.4
* @function Context menu for thumbnails
**/

package com.alexrindo.flashview.contextmenu 
{
	import com.alexrindo.flashview.image.ImageManager;
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	public class ThumbContextMenu
	{
		private var _saveImageAs:ContextMenuItem
		private var _showImage:ContextMenuItem
		
		private var _images:ImageManager
		private var _thumbContextMenu:ContextMenu
		
		private var _index:int
		
		public function ThumbContextMenu(index:int) 
		{
			_index = index
			super()
			setup()
		}
		
		private function setup():void
		{
			_images = ImageManager.getInstance()
			_thumbContextMenu = new ContextMenu()
			
			_thumbContextMenu.hideBuiltInItems()
			addContextMenuItems()
		}
		
		private function addContextMenuItems():void
		{
			_saveImageAs = new ContextMenuItem("Save Image As...");
			_showImage = new ContextMenuItem("Show Image");

			_saveImageAs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, saveImage);
			_showImage.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, showImage);

			_thumbContextMenu.customItems.push(_saveImageAs,_showImage)
		}
		
		public function getContextMenu():ContextMenu
		{
			return _thumbContextMenu
		}
		
		private function saveImage(e:ContextMenuEvent):void
		{
			_images.saveImage(_index)
		}
		
		private function showImage(e:ContextMenuEvent):void
		{
			_images.showImage(_index)
		}
		
	}

}